package com.six.goods.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.six.core.entity.Category;
import com.six.core.vo.Result;
import com.six.goods.mapper.CategoryMapper;
import com.six.goods.service.CategoryService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author wang
* @description 针对表【sto_category】的数据库操作Service实现
* @createDate 2023-02-27 15:19:59
*/
@ApiModel(description = "针对表【sto_category】【类别表】的数据库操作Service实现")
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @ApiModelProperty(hidden = true)
    @Autowired
    private CategoryMapper categoryMapper;

    //分页查询
    @Override
    public Result seleAllCategory(Integer currentPage, Integer pageSize, Category category) {
        PageHelper.startPage(currentPage,pageSize);
        List<Category> categories = categoryMapper.selectAllCategory(category);
        PageInfo<Category> pageInfo=new PageInfo<>(categories);
        if (pageInfo != null){
            return new Result(2000 ,"查询成功",pageInfo);
        }else {
            return new Result(5000 ,"查询失败");
        }
    }

    //删除
    @Override
    public Result deleteCategory(Integer id) {
        int i = categoryMapper.deleteById(id);
        if (i>0){
            return new Result(2000,"删除品牌成功");
        }else {
            return new Result(5000,"删除品牌失败");
        }
    }
    //修改
    @Override
    public Result updateCategory(Category category) {
        int i = categoryMapper.updateById(category);
        if (i>0){
            return new Result(2000,"修改品牌成功");
        }else {
            return new Result(5000,"修改品牌失败");
        }

    }
    //添加
    @Override
    public Result insertCategory(Category category) {
        int i = categoryMapper.insert(category);
        if (i>0){
            return new Result(2000,"添加品牌成功");
        }else {
            return new Result(5000,"添加品牌失败");
        }
    }
    //下拉--查询
    @Override
    public Result seleCG() {
        List<Category> categories = categoryMapper.selectList(null);
        if (categories!= null){
            return new Result(2000,"查询类别成功",categories);
        }else {
            return new Result(5000,"查询类别失败");
        }
    }

    @Override
    public Category selectByCategoryname(Category category) {
        Category category1 = categoryMapper.selectByCategoryname(category);
        return category1;
    }
}




